<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Receive a message from a queue or subscription.</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="samconnection.peekall.html">SAMConnection::peekAll</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="samconnection.remove.html">SAMConnection::remove</a></div>
 <div class="up"><a href="ref.sam.html">SAM 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="samconnection.receive" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">SAMConnection::receive</h1>
  <p class="verinfo">(PECL sam &gt;= 0.1.0)</p><p class="refpurpose"><span class="refname">SAMConnection::receive</span> &mdash; <span class="dc-title">
   Receive a message from a queue or subscription.
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-samconnection.receive-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type"><a href="ref.sam.html" class="type SAMMessage">SAMMessage</a></span> <span class="methodname"><strong>SAMConnection::receive</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$target</code></span>
   [, <span class="methodparam"><span class="type">array</span> <code class="parameter">$properties</code></span>
  ] )</div>

 </div>


 <div class="refsect1 parameters" id="refsect1-samconnection.receive-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">target</code></em></dt>

     <dd>

      <p class="para">
       The identity of the queue, topic or subscription from which to receive
       the message.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">properties</code></em></dt>

     <dd>

      <p class="para">
       An optional associative array of properties describing other
       parameters to control the receive operation.
       <table class="doctable informaltable">
        
         <thead>
          <tr>
           <th>Property name</th>
           <th>Possible values</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>SAM_CORRELID</td>
           <td>
            Used to request selection of the message to receive based upon
            the correlation id string of the message.
           </td>
          </tr>

          <tr>
           <td>SAM_MESSAGEID</td>
           <td>
            Used to request selection of the message to receive based upon
            the message id string of the message.
           </td>
          </tr>

          <tr>
           <td>SAM_WAIT</td>
           <td>
            Timeout value in milliseconds to control how long the request
            should block waiting to receive a message before returning with
            a failure if no message is available on the queue or topic. The
            default value is 0 meaning wait indefinitely and should be used
            with caution as the request may wait until the overall PHP script
            processing time limit has expired if no message becomes available.
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-samconnection.receive-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   This method returns a SAMMessage object or <strong><code>FALSE</code></strong> if an error occurs.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-samconnection.receive-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4436">
    <p><strong>Example #1 Receiving a message from a queue</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$msg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$msg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;The&nbsp;receive&nbsp;failed!<br />&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Receive&nbsp;failed&nbsp;(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #DD0000">)&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4437">
    <p><strong>Example #2 Receiving a message from a queue with options</strong></p>
    <div class="example-contents"><p>
     In this example the SAM_CORRELID option is used to specify a correlation
     id string to be used to identify the message to receive. A wait timeout
     of 10 seconds is also specified.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$msg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #DD0000">'queue://receive/test'</span><span style="color: #007700">,&nbsp;array(</span><span style="color: #0000BB">SAM_CORRELID&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$token</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">SAM_WAIT&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">10000</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-4438">
    <p><strong>Example #3 Receiving a message from a subscription</strong></p>
    <div class="example-contents"><p>
     In this example we show how to receive a message from a subscription id.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$msg&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">receive</span><span style="color: #007700">(</span><span style="color: #0000BB">$subscriptionName</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$msg</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;The&nbsp;receive&nbsp;failed!<br />&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"Receive&nbsp;failed&nbsp;(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">errno</span><span style="color: #DD0000">)&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">error</span><span style="color: #DD0000">"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     Please note that $subscriptionName is a subscription id returned from an
     earlier subscribe call.
    </p></div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-samconnection.receive-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="samconnection.send.html" class="xref">SAMConnection::send</a></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="samconnection.peekall.html">SAMConnection::peekAll</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="samconnection.remove.html">SAMConnection::remove</a></div>
 <div class="up"><a href="ref.sam.html">SAM 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
